package tgc.edu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;

import tgc.edu.tms.custom.BaseEntity;

/***
 * 课表 存储所有课程的表
 */
@Entity
public class ClassSchedule extends BaseEntity<Integer> {

	private EducationalPlanner ep;// 教学计划 內含每个专业中课程的详细信息
	private Jcb jcb; // 节次表，内含星期一到星期日的所有字段
	private Classroom classroom; // 关联的教室
	private String searcherclass; // 仅针对本表班级查询用
	
	private List<TbClass> tbclass=new ArrayList<>();
	

	
	@ManyToOne
	@CreatedBy
	public EducationalPlanner getEp() {
		return ep;
	}

	public void setEp(EducationalPlanner ep) {
		this.ep = ep;
	}

	@ManyToOne
	@CreatedBy
	public Jcb getJcb() {
		return jcb;
	}

	public void setJcb(Jcb jcb) {
		this.jcb = jcb;
	}

	@ManyToOne
	@CreatedBy
	public Classroom getClassroom() {
		return classroom;
	}

	public void setClassroom(Classroom classroom) {
		this.classroom = classroom;
	}

/*	@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinTable(name="ep_tbclass",joinColumns=@JoinColumn(name="ep_id"),inverseJoinColumns=@JoinColumn(name="taclass_id"))*/
	@Transient
	public List<TbClass> getTbclass() {
		return ep.getTbclass();
	}
	
	
	public String getSearcherclass() {
		return searcherclass;
	}

	public void setSearcherclass(String searcherclass) {
		this.searcherclass = searcherclass;
	}
	@Transient
	public String getXnxq() {
		return ep == null?null:ep.getSchoolyear().getXnxq();
	}

	
	@Transient
	public String getTbclassName() {
		String str = "";
		for(TbClass s : getTbclass()) {
			str += s.getName()+"，";
		}
		if(str != "") {
			str = str.substring(0, str.length()-1);			
		}
		return str;
	}
	
	@Transient
	public String getTeacherName() {//教师
		return ep == null?null:ep.getTeacher().getName();
	}
	
	@Transient
	public String getSkjc() {
		return jcb == null?null:jcb.getJcsj();
	}
	
	
	@Transient
	public Integer getTbclassNumber() {	//上课人数
		Integer number = 0;
		if(getTbclass().size()>0&&getTbclass().get(0)!=null) {
			for (TbClass tbClass2 : getTbclass()) {
				number = number+tbClass2.getNumber();
			}
		}
		
		return number;
	}
	
	@Transient
	public String getKcmc() {//课程名称
		return ep == null?null:ep.getCurriculum().getKcmc();
	}
	
	@Transient
	public float getXf() {//学分
		return ep == null?null:ep.getCurriculum().getXf();
	}
	
	@Transient
	public Integer getZongxs() {//总学时
		return ep == null?null:ep.getCurriculum().getZhouxs();
	}
	
	@Transient
	public String getKhfs() {//考核方式
		return ep == null?null:ep.getCurriculum().getKhfs();
	}
	
	/*@Transient
	public Integer getCapacity() {//上课人数
		return classroom == null?null:classroom.getCapacity();
	}*/
	
	@Transient
	public String getJcsj() {//节次
		return jcb == null?null:jcb.getJcsj();
	}
	
	
	@Transient
	public String getXq() {//节次
		return jcb == null?null:jcb.getXq();
	}
	
	
	@Transient
	public String getZc() {//周次
		return ep == null?null:ep.getQszc()+"-"+ep.getJszc();
	}
	
	@Transient
	public String getDd() {//地点
		return classroom == null?null:classroom.getSerialNumber();
	}
	@Transient
	public String getQszc() {//起始周次
		return ep == null?null:ep.getQszc();
	}
	@Transient
	public String getJszc() {//结束周次
		return ep == null?null:ep.getJszc();
	}
	@Transient
	public String getJslx() {//安排-教室类型 多媒体教室
		return ep == null?null:ep.getJslx();
	}
	@Transient
	public Integer getClassroomId() {//安排-教室类型 多媒体教室
		return classroom.getId();
	}
	@Transient
	public String getYear() {
		return ep.getCurriculum().getProfession().getYear();
	}
	@Transient
	public String getProfession() {
		return ep.getCurriculum().getProfession().getProfesion();
	}
	@Transient
	public List<Integer> getClassId() {
		List<Integer> list=new ArrayList<>();
		if(tbclass.size()>0) {
			for(TbClass t:tbclass) {
				list.add(t.getId());
			}
		}
		return list;
	}
}
